'use strict';
import * as types from '../common/ActionTypes';
import {toastShort} from '../utils/ToastUtil';
import ApiConfig from '../configs/ApiConfig';

function request_ad(){
    return{
      type:types.FETCH_AD_SILDER_DATA_ACTION
    };
}

function receive_ad(ad_data){
  return{
    type:types.RECEIVE_AD_SILDER_DATA_ACTION,
    ad_data
  };
}

export function fetchADSlider(){
  return function (dispatch){
    //发起首次通知 开始请求了
    dispatch(request_ad())
    console.log("js_Tag","start fetchADSlider");
    //请求
    // let MyHeader = new Header();
    // MyHeader.append('User-Agent','Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0 HXMall Android');

    let MyInit_Get = {
                  method: 'GET',
                  mode: 'cors',
                  cache: 'default'
    };
    let URL = ApiConfig.ADSliderUrl;
    let request_get = new Request(URL,MyInit_Get);
    return fetch(request_get)
    .then(response => response.json())
    .then(json => dispatch(receive_ad(json)))
  }
}
